package com.woniuxy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.dto.GetEvalutionDto;
import com.woniuxy.dto.UserRelatedDto.UserTableDetails;
import com.woniuxy.entity.CommodityTable;
import com.woniuxy.entity.Evalution;
import com.woniuxy.mapper.EvalutionMapper;
import com.woniuxy.param.UpdateEvalutionParam;
import com.woniuxy.service.CommodityTableService;
import com.woniuxy.service.EvalutionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.util.DateUtil;
import com.woniuxy.util.WoniuBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import javax.print.attribute.standard.PrinterURI;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zcx,ftl,gr,rhs
 * @since 2022-01-06
 */
@Service
public class EvalutionServiceImpl extends ServiceImpl<EvalutionMapper, Evalution> implements EvalutionService {

    @Override
    public List<GetEvalutionDto> getEvalution(Integer goodId) {
        List<Evalution> evalutions = list(new QueryWrapper<Evalution>().eq("goods_id", goodId));
        List<GetEvalutionDto> getEvalutionDtos = WoniuBeanUtils.copyList(evalutions, GetEvalutionDto.class);
        return getEvalutionDtos;
    }

    public Boolean updateEvalution(UpdateEvalutionParam updateEvalutionParam){
        String s = DateUtil.parseDateLong(System.currentTimeMillis(), "yyyy-MM-dd HH:mm");
        updateEvalutionParam.setEvaluationTime(s);
        Evalution evalution = WoniuBeanUtils.copyObject(updateEvalutionParam, Evalution.class);
        UserTableDetails userTableDetails = (UserTableDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        evalution.setEvaluationAssessor(userTableDetails.getUserName());
        return save(evalution);

    }
}
